package com.netolobo.blogspot.lights;



import com.netolobo.blospot.crud.DbAdapter;

import android.app.ListActivity;
import android.database.Cursor;
import android.os.Bundle;
import android.util.Log;
import android.widget.SimpleCursorAdapter;

public class RecordsView extends ListActivity {
	private static final String RECORDS = "records";
	private String name;
	private int numberOfMoves;
	//private DbAdapter mDbHelper;


	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		
		setContentView(R.layout.records);
		
		/*try {//abrindo o banco de dados
			Principal.mDbHelper = new DbAdapter(this);

			Principal.mDbHelper.open();

		} catch (Exception e) {
			Log.v(RECORDS, " "+e);
		}*/
		
		
		
		populateRecords(Principal.mDbHelper);
		
		
		
		
	}
	
	private void populateRecords(DbAdapter mDbHelper){//pega os recordes do banco de dados
		
		Cursor recordsCursor = mDbHelper.fetchAllRecords();
    	
    	//if(c != null) {
    	startManagingCursor(recordsCursor);
    	
    	//Log.v(RECORDS, getString(recordsCursor.getColumnIndexOrThrow(mDbHelper.KEY_NAME)));
    	//String teste = getString(recordsCursor.getColumnIndexOrThrow(mDbHelper.KEY_NAME));
    	
    	/*if(recordsCursor.moveToFirst()){
    		
    		do{
    			String teste = getString(recordsCursor.getColumnIndexOrThrow(mDbHelper.KEY_NAME));
    			Log.v(RECORDS, teste);
    		}while(recordsCursor.moveToNext());
    		//int testeJogadas = getInt(recordsCursor.getColumnIndexOrThrow(mDbHelper.KEY_TIME))
    		
    	}*/
    		
    	String[] from = new String[]{mDbHelper.KEY_NAME, mDbHelper.KEY_TIME};
    	
    	
    	int[] to = new int[] { R.id.valueName, R.id.valueTime };
    	
    	//Now create an array adapter and set it to display using our row
		SimpleCursorAdapter recordsAdapter = new SimpleCursorAdapter(this,
				R.layout.records, recordsCursor, from, to);
	    
	    	
		setListAdapter(recordsAdapter);      	    	    	        	
    	    	
		
	}
	

}
